#!/bin/sh
#
# Copyright (C) 2017 Dream Property GmbH
#

source librecovery

usage()
{
	echo "Usage: ${0} [-hqtv] <vmlinuz-rescue.bin>"
	exit ${1}
}

xgetopts $@
shift $((${OPTIND} - 1))
[ "$#" -eq 1 ] || usage 1
FILENAME=`xrealpath ${1}`

! is_empty "${FILENAME}" || abort "No rescue image given"
is_readable_file "${FILENAME}" || abort "Cannot access '${FILENAME}'"
if [ -n "${RESCUE_PARTITION}" ]; then
	write_blkdev "${FILENAME}" "${RESCUE_PARTITION}"
else
	abort "Failed to write rescue image"
fi
rm -f /etc/.rescue-update-suggested
